package com.tjsinfo.tjsoa.efile.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.address.common.TAddresslistCommon;
import com.tjsinfo.tjsoa.efile.dao.EfileDao;
import com.tjsinfo.tjsoa.efile.dao.IEfileDao;
import com.tjsinfo.tjsoa.efile.vo.Efile;
import com.tjsinfo.tjsoa.system.dao.ITSystemRolesGroupDAO;
import com.tjsinfo.tjsoa.system.dao.ITSystemUserRoleGroupDAO;
import com.tjsinfo.tjsoa.system.dao.TSystemUserRoleDAO;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRole;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRoleGroup;
import com.tjsinfo.tjsoa.system.vo.User;


public class EfileUpAction extends Action {
	private IEfileDao efileDao;
	private TSystemUserRoleDAO TSystemUserRoleDAO;
	TSystemUserRole systemUserRole=null;
	
	public IEfileDao getEfileDao() {
		return efileDao;
	}

	public void setEfileDao(IEfileDao efileDao) {
		this.efileDao = efileDao;
	}

	public TSystemUserRoleDAO getTSystemUserRoleDAO() {
		return TSystemUserRoleDAO;
	}

	public void setTSystemUserRoleDAO(TSystemUserRoleDAO systemUserRoleDAO) {
		TSystemUserRoleDAO = systemUserRoleDAO;
	}


	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		// TODO Auto-generated method stub
		try {
			String cid = request.getParameter("cid");
			String type = request.getParameter("type");
			
			List<Efile> list = efileDao.findByProperty("cid", cid);
			request.setAttribute("list", list);
			
			HttpSession session=request.getSession();
			User user=(User)session.getAttribute("user");
			Integer userId=user.getUser_id();
			
			Integer RoleId=0;
			Integer roleId1=0;
			Integer roleId2=0;
			Integer roleId3=0;
			Integer roleId4=0;
			String level1="";
			String level2="";
			String level3="";
			String level4="";
			String level5="";
			List<TSystemUserRole> userRole=TSystemUserRoleDAO.findByProperty("userId", userId);
			if(userRole.size()>0){
				for (int i=0;i<userRole.size();i++){
					    systemUserRole=userRole.get(i);
					    RoleId=Integer.valueOf(systemUserRole.getRoleId());
					    if(RoleId==146)
					    	break;
					}
			}
			if(userRole.size()>0){
				for (int i=0;i<userRole.size();i++){
					    systemUserRole=userRole.get(i);
					    roleId1=Integer.valueOf(systemUserRole.getRoleId());
					    if(roleId1==190)
					    	break;
				}
			}
			if(userRole.size()>0){
				for (int i=0;i<userRole.size();i++){
					    systemUserRole=userRole.get(i);
					    roleId2=Integer.valueOf(systemUserRole.getRoleId());
					    if(roleId2==191)
					    	break;
				}
			}
			if(userRole.size()>0){
				for (int i=0;i<userRole.size();i++){
					    systemUserRole=userRole.get(i);
					    roleId3=Integer.valueOf(systemUserRole.getRoleId());
					    if(roleId3==192)
					    	break;
				}
			}
			if(userRole.size()>0){
				for (int i=0;i<userRole.size();i++){
					    systemUserRole=userRole.get(i);
					    roleId4=Integer.valueOf(systemUserRole.getRoleId());
					    if(roleId4==193)
					    	break;
				}
			}
			if(RoleId==146){
				level1="true";
			}
			if(roleId1==190){
				level2="true";
			}
			if(roleId2==191){
				level3="true";
			}
			if(roleId3==192){
				level4="true";
			}
			if(roleId4==193){
				level5="true";
			}
			if(type.equals("1")){
				request.setAttribute("level1", level1);
			}
			if(type.equals("2")){
				request.setAttribute("level2", level2);
			}
			if(type.equals("3")){
				request.setAttribute("level3", level3);
			}
			if(type.equals("4")){
				request.setAttribute("level4", level4);
			}
			if(type.equals("5")){
				request.setAttribute("level5", level5);
			}			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
